/**
 * Created by yuming619 on 2016/10/21.
 */
//rem适配手机大小�
new function (){
    var _self = this;
    _self.width = 640;//�
    _self.fontSize = 100;//
    _self.widthProportion = function(){var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;};
    _self.changePage = function(){
        document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
    }
    _self.changePage();
    window.addEventListener('resize',function(){_self.changePage();},false);
};

//轮播插件
function  slid(slid) {

    var _SlideshowTransitions = [
        { $Duration: 500, x: -0.3, $During: { $Left: [0.3,0.7] }, $Easing: { $Left: $JssorEasing$.$EaseInCubic, $Opacity: $JssorEasing$.$EaseLinear }, $Opacity: 1 }

    ];
    var options = {
        $AutoPlay: true,
        $AutoPlayInterval: 3000,
        $PauseOnHover: 1,
        $DragOrientation: 1,
        $ArrowKeyNavigation: true,
        $SlideDuration: 500,
        $SlideshowOptions: {
            $Class: $JssorSlideshowRunner$,
            $Transitions: _SlideshowTransitions,
            $TransitionsOrder: 1,
            $ShowLink: true
        },

        $ThumbnailNavigatorOptions: {
            $Class: $JssorThumbnailNavigator$,
            $ChanceToShow: 2,
            $ActionMode: 1,
            $SpacingX: 5,
            $DisplayPieces: 100,
            $ParkingPosition: 360
        }
    };

    var jssor_slider1 = new $JssorSlider$(slid, options);
    function ScaleSlider() {
        var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
        if (parentWidth)
            jssor_slider1.$ScaleWidth(Math.max(Math.min(parentWidth, 800), 300));
        else
            window.setTimeout(ScaleSlider, 300);
    }

    ScaleSlider();
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
};

//初始化地图
function mapInit () {
    mapObj = new AMap.Map('iCenter');    //默认定位：初始化加载地图时，center及level属性缺省，地图默认显示用户所在城市范围
};
//地图定位
function positioning(){
    console.log("1")
    var prompt = "";
    var lng = "";
    var lat = "";
    mapObj.plugin('AMap.Geolocation', function () {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
            maximumAge: 0,           //定位结果缓存0毫秒，默认：0
            convert: false,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            showButton: false,        //显示定位按钮，默认：true
            //buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
            //buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            showMarker: false,        //定位成功后在定位到的位置显示点标记，默认：true
            showCircle: false,        //定位成功后用圆圈表示定位精度范围，默认：true
            panToLocation: false,     //定位成功后将定位到的位置作为地图中心点，默认：true
            zoomToAccuracy:false      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
        });
        mapObj.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete',function(data){
            lng = data.position.getLng();//lng、lat分别代表经度、纬度值
            lat = data.position.getLat();
            prompt = '经度：'+ lng +'纬度：'+ lat;
            alert(prompt)

        });//返回定位信息
        AMap.event.addListener(geolocation, 'error', function(data){
            alert(data.info)
            switch(data.info) {
                case 'PERMISSION_DENIED':
                    alert('浏览器阻止了定位操作') ;
                    break;
                case 'POSITION_UNAVAILBLE':
                    alert('无法获得当前位置');
                    break;
                case 'TIMEOUT':
                    alert('定位超时');
                    break;
                default:
                    alert('未知错误');
                    break;
            }
        });
    });
}
/*function onComplete(data){
    var lng = data.position.getLng();//lng、lat分别代表经度、纬度值
    var lat = data.position.getLat();
    prompt = '经度：'+ lng +'纬度：'+ lat;
    return prompt;
    alert(prompt)
}*/
/*function onError(data){
    alert(data.info)
    switch(data.info) {
        case 'PERMISSION_DENIED':
            alert('浏览器阻止了定位操作') ;
            break;
        case 'POSITION_UNAVAILBLE':
            alert('无法获得当前位置');
            break;
        case 'TIMEOUT':
            alert('定位超时');
            break;
        default:
            alert('未知错误');
            break;
    }
} */   //返回定位出错信息
//IP定位
/*
function showCityInfo() {  //IP定位
    //加载IP定位插件
    mapObj.plugin(["AMap.CitySearch"], function() {
        //实例化城市查询类
        var citysearch = new AMap.CitySearch();
        //自动获取用户IP，返回当前城市
        citysearch.getLocalCity();
        AMap.event.addListener(citysearch, "complete", function(result){
            if(result && result.city && result.bounds) {
                var cityinfo = result.city;
                alert(cityinfo);
                //var citybounds = result.bounds;
                //document.getElementById('result').innerHTML = "您当前所在城市："+cityinfo+"";
                ////地图显示当前城市
                //mapObj.setBounds(citybounds);
            }
            else {
                var cityinfo1 = result.info;
                alert(cityinfo1);
                //document.getElementById('result').innerHTML = "您当前所在城市："+result.info+"";
            }
        });
        AMap.event.addListener(citysearch, "error", function(result){alert(result.info);});
    });
}*/
/*//定位坐标转换
//var Longitude=102.999,Latitude=103;
var startLongitude = 119.040202, andLongitude = 119.622016, startLatitude = 25.90586, andLatitude = 26.198767;
var diffLongitude = andLongitude - startLongitude,diffLatitude = andLatitude-startLatitude;
var blockNumber = 3,scope='',number = 0,blockLongitude,blockLatitude,maxNumber=4;
var block = [[1,4,7],[2,5,8],[3,6,9]];
function getPosition(Longitude,Latitude){
    var i= 0,j=0;
    blockLongitude = diffLongitude/blockNumber;
    blockLatitude = diffLatitude/blockNumber;
    for(i = 0;i<blockNumber;i++){
        for (j=0;j<blockNumber;j++){
            if((Longitude>=startLongitude+blockLongitude*i&&Longitude<startLongitude+blockLongitude*(i+1))
                &&(Latitude>=startLatitude+blockLatitude*j&&Latitude<startLatitude+blockLatitude*(j+1))){
                scope += block[i][j]+"";
                console.log(scope)
                startLongitude=startLongitude+blockLongitude*i;
                startLatitude=startLatitude+blockLatitude*j;
                diffLongitude=blockLongitude;
                diffLatitude=blockLatitude;
                number++;
                if(number>=maxNumber){
                    var data = scope;
                    startLongitude = 119.040202, andLongitude = 119.622016, startLatitude = 25.90586, andLatitude = 26.198767;
                    diffLongitude = andLongitude - startLongitude, diffLatitude = andLatitude - startLatitude;
                    blockNumber = 3, scope = '', number = 0, blockLongitude, blockLatitude, maxNumber = 4;
                    console.log(data)
                }
                else{
                    getPosition(Longitude,Latitude);
                }
            }
        }
    }
}*/
/*获取scope*/
function getScope(date){
    console.log(date);
    return date;
}
/*底部按钮切换*/
function EnterChange(x){
    if(x==1){
        document.getElementById("img1").src="images/menu-1.png"
        //document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/me-1.png"
        $("#change1").find("span").addClass("bot_focus");
        //$("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }else if(x==2){
        document.getElementById("img1").src="images/menu-1.png"
        document.getElementById("img2").src="images/me-2.png"
        document.getElementById("img3").src="images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").addClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }else if(x==3){
        document.getElementById("img1").src="images/menu-0.png"
        //document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/me-0.png"
        $("#change1").find("span").removeClass("bot_focus");
        //$("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").addClass("bot_focus");
    }else if(x==4){
        document.getElementById("img1").src="images/menu-1.png"
        document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }
}
//搜索栏监听事件
function search_top() {
    var t = 0, p = 0, change = 40;
    //var style = 1;
    /*if (style == 1) {
        $("#recommendList1").show();
        $("#recommendList2").hide();
    }*/
    window.onscroll = function () {
        t = document.documentElement.scrollTop || document.body.scrollTop;
        var seektop = document.getElementById("cmt_home_top");
        var scrollTop = $(window).scrollTop();
        if (scrollTop > change) {
            if (t > p) {
                $("#cmt_home_top").css({"transform": "translateY(-40px)"})
            }
            else {
                $("#cmt_home_top").css({"transform": "translateY(0px)"})
            }
            setTimeout(function () {
                p = t;
            }, 0)
        }
    };
}
